package ru.sviridov.sellandbuy.tasks.recipients;

import ru.sviridov.sellandbuy.RestoreActivity;
import ru.sviridov.sellandbuy.model.Response;
import ru.sviridov.sellandbuy.tasks.base.TaskRecipient;
import android.content.Context;
import android.widget.Toast;
import api.istsoft.ru.dal.Auth.PasswordAnswer;

public class GetPasswordRecipient implements TaskRecipient {

	@Override
	public void onURLError(Context context, int errorCode) {
		if(context!=null)
			Toast.makeText(context, "server error", Toast.LENGTH_SHORT).show();
	}

	@Override
	public void onJSONError(Context context, Response response) {
		if(context!=null)
			Toast.makeText(context, response.getErrorMessage(), Toast.LENGTH_SHORT).show();
	}

	@Override
	public void onSuccess(Context context, Response response) {
		if(context==null) return;
		PasswordAnswer answer = (PasswordAnswer) response.getResults()[0];
		
		((RestoreActivity)context).setQuestion(answer.getPasswordQuestion());
	}

}
